#region

using System;
using System.ComponentModel.DataAnnotations;
using ThuySan.Bussiness;

#endregion

namespace ThuySan.Models
{
    [Serializable]
    public partial class WebUserModel
    {
        #region Constructor

        public WebUserModel()
        {
        }

        public WebUserModel(WebUser value)
        {
            WebUserId = value.WebUserId;
            UserName = value.UserName;
            Password = value.Password;
            Email = value.Email;
        }

        #endregion

        #region Fields

        private String _Email;

        private String _Password;

        private String _UserName;

        private Int32 _WebUserId;

        #endregion

        #region Properties

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public Int32 WebUserId
        {
            get { return _WebUserId; }
            set { _WebUserId = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public String UserName
        {
            get { return _UserName; }
            set { _UserName = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public String Password
        {
            get { return _Password; }
            set { _Password = value; }
        }

        //[NotChanged]
        [Required(ErrorMessage = "Value is required"), StringLength(200, ErrorMessage = "Value must be under 200 characters"), RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        public String Email
        {
            get { return _Email; }
            set { _Email = value; }
        }

        #endregion

        #region Operators

        public void Update(WebUser value)
        {
            //value.WebUserId = WebUserId;
            value.UserName = UserName;
            if (!string.IsNullOrEmpty(Password))
                value.Password = Password;
            value.Email = Email;
        }

        public static implicit operator WebUserModel(WebUser obj)
        {
            return new WebUserModel(obj);
        }

        public static implicit operator WebUser(WebUserModel obj)
        {
            WebUser value = new WebUser();
            obj.Update(value);
            return value;
        }

        #endregion
    }
}
